﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
namespace DoAnTN.Buissiness
{
    class SoTangDAO
    {
        private static DBUtil objDB = new DBUtil();
        private static SqlConnection conn = null;

        public static int soTang() {
            int count = 0;
            conn = objDB.connect();
            conn.Open();
            SqlCommand objCmd= new SqlCommand("select * from SoTang",conn);
            SqlDataReader dataReader = objCmd.ExecuteReader();
            while (dataReader.Read())
            {
                count++;
            }
            conn.Close();
            return count;
        }

        public static void ThemTang(int soTangThem) {
            conn = objDB.connect();
            int soTangHienTai = soTang();
            for (int i = 0; i <= soTangThem; i++)
            {
                conn.Open();
                SqlCommand objCmd = new SqlCommand("insert into SoTang value ("+(soTangHienTai + i)+",'Tang "+(soTangHienTai + i )+"') ");
                objCmd.ExecuteNonQuery();
                conn.Close();
            }
        }
    }
}
